package fm.dongman.animefm.view.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import fm.dongman.animefm.R;
import fm.dongman.animefm.contractlib.IModel;
import fm.dongman.animefm.view.activity.WebViewActivity;
import fm.dongman.modellib.model.ArticleModel;

/**
 * 漫圈cospaly详情Adapter
 * Created by Administrator on 2017/10/25.
 */

public class CosPlayDetailsAdapter extends RecyclerView.Adapter<CosPlayDetailsAdapter.ViewHolder> {
    private List<IModel.IArticleModel> mListArticle;
    private Context mContext;

    public CosPlayDetailsAdapter(List<IModel.IArticleModel> ListComic, Context Context) {
        this.mContext = Context;
        this.mListArticle = ListComic;
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView mTitle;
        private ImageView ImgUrl1;
        private ImageView ImgUrl2;
        private ImageView ImgUrl3;
        private TextView mContext;
        private View mView;

        public ViewHolder(View itemView) {
            super(itemView);
            mTitle = (TextView) itemView.findViewById(R.id.mTvFindSheetTitle);
            ImgUrl1 = (ImageView) itemView.findViewById(R.id.mIvContentImg1);
            ImgUrl2 = (ImageView) itemView.findViewById(R.id.mIvContentImg2);
            ImgUrl3 = (ImageView) itemView.findViewById(R.id.mIvContentImg3);
            mContext= (TextView) itemView.findViewById(R.id.mTvFindSheetContext);
            mView=itemView;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_comic_cosplay, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final ArticleModel article = (ArticleModel) mListArticle.get(position);
        holder.mTitle.setText(article.getTitle());
        holder.mContext.setText(article.getSummary());
        String[] strAyy = article.getThumbs();
        // Log.i("aaaaaaaaaa",strAyy[0]+","+strAyy[1]+","+strAyy[2]);
        Glide.with(mContext).load(strAyy[0]).into(holder.ImgUrl1);
        Glide.with(mContext).load(strAyy[1]).into(holder.ImgUrl2);
        Glide.with(mContext).load(strAyy[2]).into(holder.ImgUrl3);

        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!(mContext instanceof Activity)) {
                    throw new RuntimeException(mContext.toString() + " 必须是Activity!");
                } else {
                    mContext.startActivity(WebViewActivity.getIntent(mContext, article.getArticleURL()));
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        return mListArticle.size();
    }


}
